﻿using HR.Config;
using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Concurrent;

namespace HR.Controllers
{
    public class SalaryGrantController : Controller
    {
        private readonly ISalaryGrantService isgs;
        private readonly ISalaryGrantDetailsService isgds;

        public SalaryGrantController(ISalaryGrantService isgs, ISalaryGrantDetailsService isgds)
        {
            this.isgs = isgs;
            this.isgds = isgds;
        }

        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬发放登记视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 根据薪酬发放方式进行查询
        /// </summary>
        /// <param name="flagid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryGrantFindWay(int flagid)
        {
            List<salary_grant> list = await isgs.SalaryGrantFindWay(flagid);
            return Json(list);
        }
        /// <summary>
        /// 根据薪酬发放ID查询其薪酬发放的详细信息,没有发放过工资的
        /// </summary>
        /// <param name="flagid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryGrantDetailByIdFalse(string salary_grant_id)
        {
            List<salary_grant_detail> list = await isgds.SalaryGrantDetailByIdFalse(salary_grant_id);
            return Json(list);
        }
        /// <summary>
        /// 根据薪酬发放ID查询其薪酬发放的详细信息，发放过工资的
        /// </summary>
        /// <param name="flagid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryGrantDetailById(string salary_grant_id)
        {
            List<salary_grant_detail> list = await isgds.SalaryGrantDetailById(salary_grant_id);
            return Json(list);
        }
        
        /// <summary>
        /// 薪酬发放登记提交修改按钮
        /// </summary>
        /// <param name="sgd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryGrantDetailUpdate(string salary_grant_details)
        {
            List<salary_grant_detail>? list = JsonConvert.DeserializeObject<List<salary_grant_detail>>(salary_grant_details);
            int res = await isgds.SalaryGrantDetailUpdate(list);
            return Json(res);
        }
        [HttpGet]
        /// <summary>
        /// 薪酬发放登记复核视图
        /// </summary>
        /// <returns></returns>
        [TypeFilter(typeof(RoleFilterAttribute))]
        [HttpGet]
        public IActionResult IndexCheck()
        {
            return View();
        }
        /// <summary>
        /// 分页查询薪酬发放简略表并未做复核过的数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> SalaryGrantPGFills(int pgsize,int pgcurrent)
        {
            Paging<salary_grant> pg = await isgs.SalaryGrantPGFills(pgsize,pgcurrent);
            return Json(pg);
        }
        /// <summary>
        /// 薪酬发放登记复核确认复核接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryGrantCheck([FromBody] salary_grant_Check sgc)
        {
            List<salary_grant_detail>? list = JsonConvert.DeserializeObject<List<salary_grant_detail>>(sgc.salary_grant_detailsJson);
            int res = await isgs.SalaryGrantCheck(sgc, list);
            return Json(res);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 薪酬发放查询视图
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult IndexFind()
        {
            return View();
        }
        /// <summary>
        /// 薪酬发放模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SalaryGrantFind([FromBody] SalaryStandardDimPage ssdp)
        {
            Paging<salary_grant> pg = await isgs.SalaryGrantFind(ssdp);
            return Json(pg);
        }
        
    }
}
